//
//  MineViewController.swift
//  iOSProjectExtensionSwift
//
//  Created by HBGG on 2020/7/5.
//  Copyright © 2020 lidianchao. All rights reserved.
//

import UIKit

class MineViewController: BaseViewController,SliderTapDelegate,UIScrollViewDelegate {
    var contentScrollView: UIScrollView?
    var tabBarTitleArr: [String] = []
    var vcListArr: [UIViewController] = []
    var currentIndex: NSInteger = 0
    var sliderBtn = SliderTap()
    override func viewDidLoad() {
        super.viewDidLoad()
        tabBarTitleArr = ["全部订单","待确认","待付款","待发货","待收货","待退款","已退款","待补款","已补款","待评价"];
        sliderBtn = SliderTap(frame: CGRect(x: 0, y:200, width: DeviceWidth, height: 35))
        sliderBtn.delegate = self
        sliderBtn.itemsTitle = tabBarTitleArr
        sliderBtn.currentItemIndex = 0
        addListButtonChildViewController()
        self.view.addSubview(sliderBtn)
        // Do any additional setup after loading the view.
    }
    func addListButtonChildViewController() {
        let scroolY = sliderBtn.maxY+16
        let scroolH = DeviceHeight - scroolY - Height_SafeAreaTabBa
        contentScrollView = UIScrollView(frame: CGRect(x: 0, y: scroolY, width: DeviceWidth, height: scroolH))
        contentScrollView!.showsHorizontalScrollIndicator = false;
        contentScrollView!.delegate = self;
        //设置scrollView能够分页
        contentScrollView!.isPagingEnabled = true;
        //关闭scrollView的弹簧效果
        contentScrollView!.bounces = false;
        self.view.addSubview(contentScrollView!)
        //添加子视图控制器
        addChildViewControllers()
    }
    func addChildViewControllers() {
        for i in 0...tabBarTitleArr.count-1 {
            let list = MineTestViewController()
            list.view.frame = CGRect(x: DeviceWidth*CGFloat(i), y: 0, width: DeviceWidth, height: self.contentScrollView!.viewHeight)
            vcListArr.append(list)
        }
        for i in 0...vcListArr.count-1 {
            contentScrollView!.addSubview(vcListArr[i].view)
            contentScrollView!.contentSize = CGSize(width: vcListArr[i].view.maxX, height: contentScrollView!.viewHeight)
        }
        sliderBtn.currentItemIndex = 0
    }
    func listTabBar(listTabBar: SliderTap, selectIndex: NSInteger) {
        currentIndex = selectIndex
        if(contentScrollView == nil) {
            return
        }
        contentScrollView!.setContentOffset(CGPoint(x: CGFloat(currentIndex) * DeviceWidth, y: 0.0), animated: true)
    }
    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        if(scrollView.contentOffset.x/DeviceWidth == CGFloat(currentIndex)) {
            return
        }
        currentIndex = NSInteger(scrollView.contentOffset.x/DeviceWidth)
        sliderBtn.currentItemIndex = currentIndex
    }
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
